import instance from '@/utils/axios'

/* home首页接口 */

//1.文章频道列表
function getChannelList(){
    return instance({
        url:'/v1_0/channels',
        method:'get'
    })
}
//导出接口
export { getChannelList }


//2.文章列表
function getArticleList({channel_id,timestamp}){
    return instance({
        url:'/v1_0/articles',
        method:'get',
        params:{
            /* 固定参数，写1即可 */
            with_top:1,
            channel_id,
            timestamp
        } 
    })
}
//导出接口
export { getArticleList }

//3.文章详细信息
function getArticleInfo(id){
    /* 参数是文章id:直接在路径后面写(id作为路径一部分)
    格式： url/id
    */
    return instance({
        url:`/v1_0/articles/${id}`,
        method:'get'
    })
}
//导出接口
export {getArticleInfo}

//4.关注接口
//4.1 关注
function addFollowing(target){
    return instance({
        url:`/v1_0/user/followings`,
        method:'post',
        data:{target}
    })
}

//4.2 取消关注
function removeFollowing(target){
    /* 参数是用户id:直接在路径后面写(id作为路径一部分)
    格式： url/id
    */
    return instance({
        url:`/v1_0/user/followings/${target}`,
        method:'delete'
    })
}

export { addFollowing,removeFollowing }

//5.点赞接口
//5.1 点赞
function addLikings(target){
    return instance({
        url:`/v1_0/article/likings`,
        method:'post',
        data:{target}
    })
}

//5.2 取消关注
function removeLikings(target){
    /* 参数是文章id:直接在路径后面写(id作为路径一部分)
    格式： url/id
    */
    return instance({
        url:`/v1_0/article/likings/${target}`,
        method:'delete'
    })
}

export { addLikings,removeLikings }

//6.不喜欢接口
//6.1 不喜欢
function addDisLikes(target){
    return instance({
        url:`/v1_0/article/dislikes`,
        method:'post',
        data:{target}
    })
}

//6.2 取消不喜欢
function removeDisLikes(target){
    /* 参数是文章id:直接在路径后面写(id作为路径一部分)
    格式： url/id
    */
    return instance({
        url:`/v1_0/article/dislikes/${target}`,
        method:'delete'
    })
}

export { addDisLikes,removeDisLikes }

//7. 搜索推荐词列表
function getSuggestion(q){
    return instance({
        url:'/v1_0/suggestion',
        method:'get',
        params:{ q }
    })
}

export { getSuggestion }